<?php ob_start(); ?>
<?php
$scriptWindowMsg = "
    $(function() {
        $('a#close').click(function() {
            window.close();
        });
    });";
$this->Html->scriptBlock($scriptWindowMsg, array('inline' => false));
?>
<style>
    .title-tbl {
        background-color: #dedddd;
        font-size: 13px;
        font-weight: bold;
    }
    thead {
      background-color: #dedddd;
    }
    .tbl-broking td {
        border-bottom: 1px solid #333333;
        border-left: 1px solid;
        border-right: 1px solid #333333;
        height: 30px;
    }
    .td-payment-r {
        width: 100px;
    }
    td {
        text-align: center;
        vertical-align: middle;
    }
    .tbl-broking tr {
        height: 30px;
        margin: 0;
        padding: 0;
    }
    .tbl-broking {
        border-left: 1px solid #333333;
        border-top: 1px solid #333333;
        height: auto;
        margin: 0;
        padding: 0;
        table-layout: fixed;
        width: 100%;
    }
    .tbl-broking-r td {
        border-color: #333333;
        border-style: solid;
        border-width: 1px;
        height: 30px;
    }
    table {
        border-collapse: collapse;
        border-spacing: 0;
    }
    .clearfix:after {
        clear: both;
        content: ".";
        display: block;
        font-size: 0;
        height: 0;
        visibility: hidden;
    }
    .clearfix:after {
        clear: both;
        content: ".";
        display: block;
        height: 0;
        visibility: hidden;
    }
    .wrapper-table {
        height: auto;
        margin: 13px 0 0;
        padding: 0;
        width: 100%;
    }
    .clearfix {
        display: block;
    }
    .title-body-content {
        color: #A0002A;
        font-size: 17px;
        font-weight: bold;
        height: auto;
        margin: 0 0 0;
        padding: 0;
        text-align: center;
        width: 100%;
    }
    .wrapper-content-body {
        background-color: White;
        height: auto;
        margin: 0 0 60px;
        padding: 0 16px 0;
        width: 96.8%;
    }
    .wrapper-body {
        background-color: White;
        height: auto;
        margin: 0;
        padding: 10px 0 0;
        width: 100%;
    }
    .hightlight {
        background-color: yellow;
        font-weight: bold;
    }
    .line-content-tbl {
        font-size: 12px;
    }
</style>
<div class="title-body-content"><?php echo $title_for_layout; ?></div>
<div class="wrapper-table clearfix">
  <?php
    foreach ($trakingreports AS $obj) {
        //php_debug($obj);
    ?>   
    <table class="tbl-broking" border="1" style="margin-top: 10px;">
        <thead>
            <tr class="title-tbl" >
                <td class="td-payment"><?php echo __('Payment#'); ?></td>
                <td class="td-ref-payment"><?php echo __('Reference#'); ?></td>
                <td class=""><?php echo __('Amount'); ?></td>
                <td class=""><?php echo __('Paid Amount'); ?></td>
                <td class=""><?php echo __('100% to AIH'); ?></td>
        <?php
        $totalamount = 0;
        foreach ($obj AS $trakingreport) {
            //php_debug($trakingreport);
            $totalamount = $totalamount + $trakingreport['Placementdetailt']['contact_amount'];
            $checked = ($trakingreport['Placementdetailt']['paid'] == '1') ? '&#10003;' : '';
            echo '
                <td> To ' . $trakingreport['Placementdetailt']['contact_name'] . '</td>';
            
        }
        ?>
            </tr>
        </thead>
        <tr>
            <td class="td-payment">
                <a href="<?php echo Router::url('/admin/paymentschedules/payment_records/'.$obj[1]['Placementdetailt']['paymentid'], true); ?>" target="blank">
                    <?php echo $obj[1]['Placementdetailt']['paymentrefid'] ?>
                </a>
            </td>
            <td class="td-ref-payment">
                <a href="<?php echo Router::url('/admin/accountresumes/edit/'.$obj[1]['Placementdetailt']['accid'], true); ?>" target="blank">
                    <?php echo $obj[1]['Placementdetailt']['refid_edit'] ?>
                </a>
            </td>
            <td class="hightlight" style="text-align: right; padding-right:3px;">
                <?php echo $obj[1]['Placementdetailt']['currency'] . ' ' . number_format($obj[1]['Placementdetailt']['broker_amount'],2); ?>
            </td>
            <td class="hightlight" style="text-align: right; padding-right:3px;">
                <?php echo $obj[1]['Placementdetailt']['currency'] . ' ' . number_format($obj[1]['Placementdetailt']['paid_amount'],2); ?>
            </td>
            <td class="td-ref-payment">
                <?php if($obj[0]['Placementdetailt']['alltoaih'] == 1) { echo '&#10003;'; }else{ echo '';} ?>
            </td>
    <?php
    foreach ($obj AS $trakingreport) {
        //$checked = ($trakingreport['Placementdetailt']['paid'] == 1) ? '&#10003;' : '';
		if($trakingreport['Placementdetailt']['paid'] == 1){
			$checked = $trakingreport['Placementdetailt']['currency'] . ' ' . number_format($trakingreport['Placementdetailt']['paid_amount'] - $trakingreport['Placementdetailt']['aih_amount'] ,2);
		}else{
			$checked = '';
		}
        if($trakingreport['Placementdetailt']['contact_name'] == 'AIH Commission'){
            $checked = ($trakingreport['Placementdetailt']['paid_to_aih'] == 1) ? '&#10003;' : '';
			//$checked = ($trakingreport['Placementdetailt']['paid_to_aih'] == 1) ? number_format($trakingreport['Placementdetailt']['aih_amount'] ,2) : '';
        }
        echo '
            <td class="td-paid">
                ' . $checked .  '
            </td>';
    }
    ?>
        </tr>
    </table>
    <?php 
    } 
    ?>
</div>
<?php
    $HtmlCode= ob_get_contents();
    ob_end_flush();
    $HtmlCode1 = str_replace('&#10003;', '<img src="img/tick.gif" alt="" />', $HtmlCode);
    $file = '/home/johnso28/public_html/aihreinsurance.com/dompdf/aih/payment_tracking_report.html';
    file_put_contents($file, $HtmlCode1);
?>

<div class="wrapper-button-form clearfix">
    <div class="button-form clearfix">
        <div class="button-aihre button-blue"><a href="JavaScript:void(0)" title="CLOSE" id="close"><?php echo __('CLOSE'); ?></a></div>
    </div>
</div>
<div class="wrapper-button-form clearfix">
    <div class="button-form clearfix">
        <a href="http://<?php echo $_SERVER['HTTP_HOST']; ?>/dompdf/dompdf.php?base_path=aih/&input_file=payment_tracking_report.html&paper=a4">Download PDF</a>
        &nbsp; | &nbsp;
		<?php echo $this->Html->link('Download Excel', '/phpexcel/paymenttracking.php?ids=' . $ids, null, array()); ?>
    </div>
</div>